from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-03 14:02:27.111347
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 03, May, 2022
Time: 14:02:32
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.1560
Nobs: 645.000 HQIC: -49.5376
Log likelihood: 7906.99 FPE: 2.40435e-22
AIC: -49.7796 Det(Omega_mle): 2.09346e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.325711 0.061655 5.283 0.000
L1.Burgenland 0.105035 0.039261 2.675 0.007
L1.Kärnten -0.110350 0.020585 -5.361 0.000
L1.Niederösterreich 0.196169 0.081980 2.393 0.017
L1.Oberösterreich 0.119029 0.080948 1.470 0.141
L1.Salzburg 0.258289 0.041724 6.190 0.000
L1.Steiermark 0.043805 0.054854 0.799 0.425
L1.Tirol 0.106039 0.044241 2.397 0.017
L1.Vorarlberg -0.063946 0.039110 -1.635 0.102
L1.Wien 0.026116 0.071708 0.364 0.716
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052420 0.131774 0.398 0.691
L1.Burgenland -0.032927 0.083911 -0.392 0.695
L1.Kärnten 0.040211 0.043995 0.914 0.361
L1.Niederösterreich -0.189354 0.175213 -1.081 0.280
L1.Oberösterreich 0.447978 0.173008 2.589 0.010
L1.Salzburg 0.285635 0.089175 3.203 0.001
L1.Steiermark 0.105955 0.117237 0.904 0.366
L1.Tirol 0.313769 0.094555 3.318 0.001
L1.Vorarlberg 0.021817 0.083588 0.261 0.794
L1.Wien -0.037058 0.153258 -0.242 0.809
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190168 0.031587 6.020 0.000
L1.Burgenland 0.090281 0.020114 4.488 0.000
L1.Kärnten -0.007987 0.010546 -0.757 0.449
L1.Niederösterreich 0.248963 0.042000 5.928 0.000
L1.Oberösterreich 0.157418 0.041472 3.796 0.000
L1.Salzburg 0.040441 0.021376 1.892 0.059
L1.Steiermark 0.024983 0.028103 0.889 0.374
L1.Tirol 0.086888 0.022666 3.833 0.000
L1.Vorarlberg 0.054089 0.020037 2.699 0.007
L1.Wien 0.116253 0.036737 3.164 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112511 0.031731 3.546 0.000
L1.Burgenland 0.045450 0.020206 2.249 0.024
L1.Kärnten -0.014338 0.010594 -1.353 0.176
L1.Niederösterreich 0.180578 0.042192 4.280 0.000
L1.Oberösterreich 0.327158 0.041661 7.853 0.000
L1.Salzburg 0.101667 0.021474 4.734 0.000
L1.Steiermark 0.110364 0.028231 3.909 0.000
L1.Tirol 0.097881 0.022769 4.299 0.000
L1.Vorarlberg 0.059342 0.020128 2.948 0.003
L1.Wien -0.021351 0.036905 -0.579 0.563
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.115255 0.059118 1.950 0.051
L1.Burgenland -0.043197 0.037645 -1.147 0.251
L1.Kärnten -0.046538 0.019738 -2.358 0.018
L1.Niederösterreich 0.144030 0.078606 1.832 0.067
L1.Oberösterreich 0.158067 0.077617 2.037 0.042
L1.Salzburg 0.283155 0.040007 7.078 0.000
L1.Steiermark 0.055779 0.052596 1.061 0.289
L1.Tirol 0.167115 0.042421 3.939 0.000
L1.Vorarlberg 0.095798 0.037500 2.555 0.011
L1.Wien 0.072762 0.068756 1.058 0.290
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060223 0.046505 1.295 0.195
L1.Burgenland 0.030353 0.029613 1.025 0.305
L1.Kärnten 0.051531 0.015527 3.319 0.001
L1.Niederösterreich 0.206327 0.061836 3.337 0.001
L1.Oberösterreich 0.322599 0.061057 5.284 0.000
L1.Salzburg 0.038339 0.031471 1.218 0.223
L1.Steiermark 0.006975 0.041375 0.169 0.866
L1.Tirol 0.130210 0.033370 3.902 0.000
L1.Vorarlberg 0.063897 0.029500 2.166 0.030
L1.Wien 0.090436 0.054087 1.672 0.095
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172467 0.055868 3.087 0.002
L1.Burgenland 0.005927 0.035576 0.167 0.868
L1.Kärnten -0.065239 0.018653 -3.498 0.000
L1.Niederösterreich -0.097833 0.074286 -1.317 0.188
L1.Oberösterreich 0.204329 0.073350 2.786 0.005
L1.Salzburg 0.054924 0.037808 1.453 0.146
L1.Steiermark 0.240231 0.049705 4.833 0.000
L1.Tirol 0.501389 0.040089 12.507 0.000
L1.Vorarlberg 0.061034 0.035439 1.722 0.085
L1.Wien -0.074882 0.064977 -1.152 0.249
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.147671 0.062005 2.382 0.017
L1.Burgenland 0.004835 0.039483 0.122 0.903
L1.Kärnten 0.060013 0.020702 2.899 0.004
L1.Niederösterreich 0.183834 0.082445 2.230 0.026
L1.Oberösterreich -0.061243 0.081407 -0.752 0.452
L1.Salzburg 0.207546 0.041961 4.946 0.000
L1.Steiermark 0.134259 0.055164 2.434 0.015
L1.Tirol 0.070587 0.044492 1.587 0.113
L1.Vorarlberg 0.144026 0.039331 3.662 0.000
L1.Wien 0.110311 0.072114 1.530 0.126
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.378008 0.036456 10.369 0.000
L1.Burgenland -0.001124 0.023215 -0.048 0.961
L1.Kärnten -0.021835 0.012172 -1.794 0.073
L1.Niederösterreich 0.211480 0.048474 4.363 0.000
L1.Oberösterreich 0.226177 0.047864 4.725 0.000
L1.Salzburg 0.038730 0.024671 1.570 0.116
L1.Steiermark -0.013992 0.032435 -0.431 0.666
L1.Tirol 0.095367 0.026160 3.646 0.000
L1.Vorarlberg 0.052874 0.023125 2.286 0.022
L1.Wien 0.036476 0.042400 0.860 0.390
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036100 0.113736 0.173188 0.141521 0.102367 0.085206 0.038530 0.210118
Kärnten 0.036100 1.000000 -0.021221 0.134319 0.052494 0.090118 0.442088 -0.060510 0.092476
Niederösterreich 0.113736 -0.021221 1.000000 0.322830 0.130296 0.283868 0.075262 0.162507 0.296219
Oberösterreich 0.173188 0.134319 0.322830 1.000000 0.221653 0.310134 0.169049 0.149875 0.249613
Salzburg 0.141521 0.052494 0.130296 0.221653 1.000000 0.131790 0.096816 0.114621 0.130198
Steiermark 0.102367 0.090118 0.283868 0.310134 0.131790 1.000000 0.140000 0.120588 0.049181
Tirol 0.085206 0.442088 0.075262 0.169049 0.096816 0.140000 1.000000 0.068904 0.149375
Vorarlberg 0.038530 -0.060510 0.162507 0.149875 0.114621 0.120588 0.068904 1.000000 0.007186
Wien 0.210118 0.092476 0.296219 0.249613 0.130198 0.049181 0.149375 0.007186 1.000000